<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单编号：</label>
                            <input type="text" name="orderNo"/>
                        </li>
                        <li>
                            <label>订单价格：</label>
                            <input type="text" name="orderPrice"/>
                        </li>
                        <li>
                            <label>订单状态：</label>
                            <select name="orderStatus"
                                    th:with="type=${@dict.getType('${dictType}')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wx:order:add">-->
<!--                <i class="fa fa-plus"></i> 添加-->
<!--            </a>-->
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="wx:order:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-primary single disabled" onclick="send()"
               shiro:hasPermission="wx:order:edit">
                <i class="fa fa-send"></i> 发货
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="wx:order:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wx:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('wx:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('wx:order:remove')}]];

    var orderStatusDatas = [[${@dict.getType('orderStatusDatas')}]];
    var prefix = ctx + "wx/order";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '订单编号',

                },
                {
                    field: 'orderPrice',
                    title: '订单价格',

                },
                {
                    field: 'userName',
                    title: '下单用户',

                },
                {
                    field: 'goodsName',
                    title: '下单商品',

                },

                {
                    field: 'orderStatus',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '下单时间',

                },
                {
                    field: 'payTime',
                    title: '付款时间',

                },

                ]
        };
        $.table.init(options);
    });

    function send() {
        var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
        if (row.orderStatus !='2'){
            $.modal.alertWarning('非付款状态的订单，无法发货!');
            return;
        }

        $.ajax({
            url: prefix+'/send',
            type: 'post',
            data: {id: row.id},
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (data) {
                $.modal.alertSuccess(data.msg)
                $.modal.closeLoading();
                $.table.refresh()
            }
        })
    }
</script>
</body>
</html>